home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z12.ADF / DRIVEM.ARC / ARCfile.64 / epfix.asm < prev    next >
Assembly Source File  |  1986-07-11  |  8KB  |  377 lines

  1. *
  2. * EPFix.asm: Copyright 1986 by Limited Reality, Inc.
  3. *
  4.  
  5.     INCLUDE "exec/types.i"
  6.     INCLUDE "libraries/dos.i"
  7.  
  8. XLIB    MACRO            ;avoid _LVO on XREF's
  9.     XREF    _LVO\1
  10.     ENDM
  11.  
  12. SysCall    MACRO            ;avoid typing _LVO every time
  13.     jsr    _LVO\1(a6)
  14.     ENDM
  15.  
  16. WriteFile MACRO ;File,String,Len
  17.     move.l    \1,d1        ;file to write
  18.     move.l    \2,d2        ;string to write
  19.     move.l    \3,d3        ;number of chars to write
  20.     SysCall    Write        ;write 'em
  21.     ENDM
  22.  
  23.     XREF    _AbsExecBase    ;base address for exec library
  24.     XLIB    OpenLibrary    ;exec: open a library
  25.     XLIB    AllocMem    ;      allocate memory block
  26.     XLIB    FreeMem        ;      free memory block
  27.  
  28.     XLIB    Lock        ;DOS functions
  29.     XLIB    UnLock
  30.     XLIB    DupLock
  31.     XLIB    CurrentDir
  32.     XLIB    Examine
  33.     XLIB    ExNext
  34.     XLIB    Output
  35.     XLIB    Open
  36.     XLIB    Close
  37.     XLIB    Read
  38.     XLIB    Write
  39.     XLIB    Exit
  40.  
  41. * StoredFile structure
  42. EPLen    EQU    0        ;size of the file in this block
  43. EPFile    EQU    EPLen+4        ;contents of the file start here
  44.  
  45. ***************************** initialization ***************************
  46.  
  47.     movem.l    d0/a0,-(SP)
  48.     move.l    #FSpec1,d0
  49.     move.l    d0,FileSpec
  50.  
  51. **************************** open DOS library **************************
  52.  
  53.     move.l    _AbsExecBase,a6    ;find exec library
  54.     move.l    #DOS_Name,a1    ;pass string containing name
  55.     clr.l    d0        ;expect any version
  56.     SysCall    OpenLibrary
  57.     move.l    d0,a6
  58.     move.l    a6,DosLibrary
  59.     beq    Abort2
  60.  
  61. *************************** find output device ***************************
  62.  
  63.     SysCall    Output        ;get a file handle, already open
  64.     move.l    d0,StdOut
  65.     beq    Abort2
  66.  
  67. *************************** check command line ***************************
  68.  
  69.     movem.l    (SP)+,a0/d0
  70.     cmpi.l    #1,d0
  71.     beq    GoToIt
  72.  
  73. ScanArgs:
  74.     cmpi.b    #' ',(a0)
  75.     bne    OkSoFar
  76.     addq.l    #1,a0
  77.     subq.l    #1,d0
  78.     beq    BadArgs
  79.     bra    ScanArgs
  80.  
  81. OkSoFar:
  82.     andi.b    #$5f,(a0)
  83.     cmpi.b    #'J',(a0)
  84.     bne    BadArgs
  85. DoJX:
  86.     move.l    #FSpec2,d0
  87.     move.l    d0,FileSpec
  88.     move.b    #1,d0
  89.     move.b    d0,JXFlag
  90.  
  91. GoToIt:
  92.     WriteFile StdOut,#IntroMsg1,#IM1Len
  93.     move.l    #JXFlag,a3
  94.     cmpi.b    #1,(a3)
  95.     bne    GTI2
  96.     WriteFile StdOut,#JX80,#JXLen
  97. GTI2:
  98.     WriteFile StdOut,#IntroMsg2,#IM2Len
  99.  
  100. ************************ find DEVS:printers directory *******************
  101. ChangeDir:
  102.     move.l    #Path,d1
  103.     move.l    #ACCESS_READ,d2
  104.     SysCall    Lock        ;try to find this device
  105.     move.l    d0,DirLock
  106.     beq    Abort2        ;got it?
  107.     SysCall    CurrentDir    ;make it current
  108.     move.l    d0,OldDir    ;save old directory
  109.  
  110. *********************** get data about directory **************************
  111.  
  112. ExamineDir:
  113.     move.l    DirLock,d1
  114.     move.l    #DirItem,d2
  115.     SysCall    Examine        ;get data about dir
  116.     tst.l    d0        ;successful?
  117.     beq    Abort        ; no: quit
  118. NextFile:
  119.     move.l    DirLock,d1
  120.     move.l    #DirItem,d2
  121.     movea.l    DosLibrary,a6
  122.     SysCall    ExNext        ;get data about next entry
  123.     tst.l    d0        ;is there another?
  124.     beq    NotFound    ; no: quit
  125.     tst.l    fib_DirEntryType+DirItem ;is dir?
  126.        bpl    NextFile    ;can't use it
  127.  
  128. *********************** does it match the file spec **********************
  129.  
  130.     movea.l    #DirItem+fib_FileName,a0
  131.     movea.l    FileSpec,a1
  132. FMatchLoop:
  133.     move.b    (a1),d0        ;get char from FSpec
  134.     cmp.b    (a0),d0        ;match?
  135.     bne    NextFile
  136. CharMatch:
  137.     tst.b    d0        ;matched null terminators?
  138.     beq    Match        ; yes: success
  139. NotFNEnd:
  140.     addq.l    #1,a1
  141.     addq.l    #1,a0
  142.     bra    FMatchLoop
  143. Match:
  144.  
  145. ************* allocate space to hold file info and contents ************
  146.  
  147. * space needed:
  148. *  4-- length of file
  149. * ??-- contents of file: fib_Size
  150. * total: length of file+4
  151.  
  152.     move.l    DirItem+fib_Size,d0 ;length of file
  153.     addq.l    #4,d0        ;+4
  154.     clr.l    d1        ;request any kind of RAM
  155.     movea.l    _AbsExecBase,a6
  156.     SysCall    AllocMem
  157.     tst.l    d0        ;successful?
  158.     beq    NoMem        ;  no:  quit
  159.  
  160. ********************* load the file into RAM *************************
  161.  
  162.     move.l    d0,FilePTR    ;save file pointer for later use
  163.     move.l    d0,a1
  164.     move.l    DirItem+fib_Size,(a1)+ ;store file size
  165.     move.l    DirLock,d1
  166.     movea.l    DosLibrary,a6
  167.     SysCall    CurrentDir    ;make it current
  168.     move.l    #DirItem+fib_FileName,d1
  169.     move.l    #MODE_OLDFILE,d2
  170.     SysCall    Open        ;Open the file
  171.     move.l    d0,d1
  172.     move.l    d0,FileHandle
  173.     move.l    FilePTR,d2
  174.     addq.l    #EPFile,d2
  175.     move.l    DirItem+fib_Size,d3
  176.     SysCall    Read        ;Read it
  177.     move.l    FileHandle,d1
  178.     SysCall    Close        ;be nice
  179.  
  180. ******************************* patches *********************************
  181.  
  182.     movea.l    FilePTR,a4    ;point to beginning of file
  183.     addq.l    #EPFile,a4
  184.  
  185.     move.b    #72,117(a4)    ;offset 117: (Same for both drivers)
  186.                 ;  changed from 82 to 72 dpi for
  187.                 ;  correct graphic renditions.
  188.  
  189.     move.l    #JXFlag,a3    ;check to see if we are modifying
  190.     cmpi.b    #1,(a3)        ;  the JX-80 driver
  191.     beq    ModJX        ;  if so, do it right!
  192.  
  193. ModEp:                ; (Mods for standard Epson)
  194.     move.b    #3,2665(a4)    ;offset 2665:
  195.                 ;  changed from 02 to 03 to
  196.                 ;  tell new number of data
  197.                 ;  bytes to read to set
  198.                 ;  correct line spacing.
  199.  
  200.     move.b    #65,3339(a4)    ;offset 3339, 3340:
  201.     move.b    #8,3340(a4)    ;  changed from $31,0 to $41,8
  202.                 ;  to set correct line spacing
  203.                 ;  of 8/72" instead of 7/72"
  204.     bra    EPFixDone
  205.  
  206. ModJX:                ; (Mods for JX-80)
  207.     move.b    #3,2893(a4)    ;offset 2893:
  208.                 ;  changed from 02 to 03 to
  209.                 ;  tell new number of data
  210.                 ;  bytes to read to set
  211.                 ;  correct line spacing.
  212.  
  213.     move.b    #65,3945(a4)    ;offset 3945, 3946:
  214.     move.b    #8,3946(a4)    ;  changed from $31,0 to $41,8
  215.                 ;  to set correct line spacing
  216.                 ;  of 8/72" instead of 7/72"
  217.  
  218. ********************** clean up house and leave ************************
  219.  
  220. EPFixDone:
  221.     bsr    SaveFile    ;write out the file
  222.     bsr    RestoreDir    ;restore original directory
  223.     move.l    DirLock,d1    ;free lock structure
  224.     SysCall    UnLock
  225.     WriteFile StdOut,#Fini,#FLen ;tell 'em we're done
  226.     bra    Abort2        ;and end
  227.  
  228. ********************* error handling routines **************************
  229.  
  230. BadArgs:            ;bad command line arguments
  231.     WriteFile StdOut,#BAMsg,#BALen
  232.     bra    Abort2
  233.  
  234. NotFound:
  235.     WriteFile StdOut,#NoFile,#NFLen
  236.     bra    Abort1
  237.  
  238. NoMem:                ;file too big to load
  239.     movea.l    DosLibrary,a6
  240.     WriteFile StdOut,#NoMemMSG,#NMMLen
  241.     bra    Abort
  242.  
  243. WriteFailed:            ;file is open
  244.     move.l    FileHandle,d1
  245.     SysCall    Close        ;close the file
  246.  
  247. SaveAbort:
  248.     WriteFile StdOut,#FailedMSG,#FailedLen
  249.  
  250. Abort:
  251.     bsr    FreeRAM        ;free all memory
  252. Abort1:
  253.     bsr    RestoreDir    ;restore original current directory
  254.     move.l    DirLock,d1
  255.     SysCall    UnLock        ;unlock source directory
  256. Abort2:
  257.     SysCall    Exit        ;flee!
  258.  
  259. ********************* subroutine to save the file **********************
  260.  
  261. SaveFile:
  262.     movea.l    FileSpec,a3
  263.     move.l    a3,d1
  264.     move.l    #MODE_NEWFILE,d2
  265.     SysCall    Open        ;open it
  266.     move.l    d0,FileHandle
  267.     beq    SaveAbort
  268.  
  269. ***************************** write the file ***************************
  270.  
  271.     movea.l    FilePTR,a0
  272.     move.l    d0,d1        ;file handle
  273.     move.l    a0,d2
  274.     addi.l    #EPFile,d2    ;pointer to data
  275.     move.l    EPLen(a0),d3    ;file length
  276.     SysCall    Write
  277.     cmpi.l    #-1,d0        ;error
  278.     beq    WriteFailed
  279.     move.l    FileHandle,d1
  280.     SysCall    Close        ;close the file
  281. SaveDone:
  282.     bsr    FreeRAM        ;free memory used for file
  283.     rts
  284.  
  285. ************** restore original current directory **********************
  286.  
  287. RestoreDir:
  288.     move.l    OldDir,d1
  289.     movea.l    DosLibrary,a6
  290.     SysCall    CurrentDir
  291.     rts
  292.  
  293. ************** give back all the allocated memory ***********************
  294.  
  295. FreeRAM:
  296.     movea.l    FilePTR,a1
  297.     move.l    (a1),d0        ;length of file
  298.     addi.l    #4,d0        ;+4 = length of block
  299.     movea.l    _AbsExecBase,a6
  300.     SysCall    FreeMem        ;free this block
  301.     rts
  302.  
  303. *************************************************************************
  304.  
  305.     SECTION    data,DATA
  306. DOS_Name:
  307.     dc.b    'dos.library',0
  308.  
  309. IntroMsg1:
  310.     dc.b    'Patching Epson'
  311. IM1Len    EQU    *-IntroMsg1
  312.  
  313. JX80:
  314.     dc.b    ' JX-80'
  315. JXLen    EQU    *-JX80
  316.  
  317. IntroMsg2:
  318.     dc.b    ' printer driver for proper operation...'
  319. IM2Len    EQU    *-IntroMsg2
  320.  
  321. Fini:
  322.     dc.b    'Done.',13,10
  323. FLen    EQU    *-Fini
  324.  
  325. BAMsg:
  326.     dc.b    'Bad Arguments!',13,10
  327. BALen    EQU    *-BAMsg
  328.  
  329. NoFile:
  330.     dc.b    'File NOT found!',13,10
  331. NFLen    EQU    *-NoFile
  332.  
  333. NoMemMSG:
  334.     dc.b    'Not enough RAM to load driver!',13,10
  335. NMMLen    EQU    *-NoMemMSG
  336.  
  337. FailedMSG:
  338.     dc.b    'Unable to write file!',13,10
  339. FailedLen EQU    *-FailedMSG
  340.  
  341. Path:
  342.     dc.b    'DEVS:printers',0    ;directory name
  343.  
  344. FSpec1:
  345.     dc.b    'epson',0        ;file name
  346.  
  347. FSpec2:
  348.     dc.b    'epson_jx-80',0        ;alternate
  349.  
  350. JXFlag:
  351.     dc.b    0
  352.  
  353.     SECTION mem,BSS
  354.  
  355.     CNOP    0,4    ;long word align
  356. DosLibrary:
  357.     ds.l    1    ;handle for DOS Library
  358.  
  359. FileSpec:
  360.     ds.l    1    ;pointer to filename
  361. FilePTR:
  362.     ds.l    1    ;pointer to file
  363. FileHandle:
  364.     ds.l    1    ;handle of driver file
  365.  
  366. DirLock:
  367.     ds.l    1    ;lock for directory being examined
  368. OldDir:
  369.     ds.l    1    ; "    "  old directory
  370. StdOut:
  371.     ds.l    1    ;handle for default output device
  372.  
  373. DirItem:
  374.     ds.b    fib_SIZEOF
  375.  
  376.     END
  377.